﻿<Window x:Class="LaunchPad.Core.Dialogs.ProductDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:lp="clr-namespace:LaunchPad.Core"
        xmlns:maths="clr-namespace:LaunchPad.Core.Maths"
        Title="{Binding Name}" Height="300" Width="473" Icon="/LaunchPad.Core;component/Controls/Images/product.png"
        FocusManager.FocusedElement="{Binding ElementName=nameTextBox}">
    <Window.Resources>
        <lp:TimeSpanConverter x:Key="timeSpanConverter"/>
        <maths:DistanceConverter x:Key="distanceConverter"/>
    </Window.Resources>
        <TabControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="6" >
            <TabItem Header="Product" Name="productTab">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="50"/>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="81*" />
                </Grid.RowDefinitions>
                
                <Label Grid.Column="0" Grid.Row="0" Content="Name" HorizontalAlignment="Right" Name="nameLabel" VerticalAlignment="Center" Margin="4"/>
                <TextBox Grid.Column="1" HorizontalAlignment="Stretch" Name="nameTextBox" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding Name}" TabIndex="0" Grid.ColumnSpan="2" Margin="0,6,6,6" />
                <Label Grid.Column="0" Grid.Row="1" Content="Lead In" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="4" />
                <TextBox Grid.Column="1" Grid.Row="1" FontWeight="Bold" HorizontalAlignment="Stretch" Name="leadInTextBox" VerticalAlignment="Center" TextAlignment="Left"
                         Text="{Binding Path=LeadIn, ConverterParameter=s.F, Converter={StaticResource timeSpanConverter}}" Margin="0,6,5,6" Width="288" />
                <Label Grid.Column="0" Grid.Row="2" Content="Lead Out" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="4" />
                <TextBox  Grid.Column="1" Grid.Row="2" FontWeight="Bold" HorizontalAlignment="Stretch" Name="leadOutTextBox" VerticalAlignment="Center" TextAlignment="Left"
                         Text="{Binding Path=LeadOut, ConverterParameter=s.F, Converter={StaticResource timeSpanConverter}}" Margin="0,6,5,6" Width="288" />
                <Label Grid.Column="0" Grid.Row="3" Content="Description" HorizontalAlignment="Right"  VerticalAlignment="Center" Margin="4" />
                <TextBox  Grid.Column="1" Grid.Row="3" FontWeight="Bold" HorizontalAlignment="Stretch"  Text="{Binding Description}" VerticalAlignment="Center" TextWrapping="Wrap" Grid.ColumnSpan="2" Margin="0,6,6,6" />
                <TextBlock Grid.Column="2" Grid.Row="1" HorizontalAlignment="Left" Margin="4" Text="seconds" VerticalAlignment="Center" />
                <TextBlock HorizontalAlignment="Left" Margin="4" Text="seconds" VerticalAlignment="Center" Grid.Column="2" Grid.Row="2" />
            </Grid>
        </TabItem>
        <TabItem Header="Characterization">
            <Grid>
            <DataGrid AutoGenerateColumns="False" HorizontalAlignment="Stretch" Name="samplesDataGrid" VerticalAlignment="Stretch" 
                      ItemsSource="{Binding Path=Characterization.Samples}" Margin="0,6,0,41" CanUserAddRows="True" CanUserDeleteRows="True">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Recorded On" Binding="{Binding RecordedOn}"/>
                        <DataGridTextColumn Header="Time To Apex" Binding="{Binding Path=Apex, ConverterParameter=mm:ss.f, Converter={StaticResource timeSpanConverter}}"/>
                    <DataGridTextColumn Header="Distance" Binding="{Binding Path=Distance, Converter={StaticResource distanceConverter}}"/>
                </DataGrid.Columns>
                </DataGrid>
                <Label Content="Average Delay" Height="28" HorizontalAlignment="Left" Margin="6,0,0,6" VerticalAlignment="Bottom" />
                <Label Content="{Binding Path=Characterization.AverageAdjustedApex, ConverterParameter=mm:ss.f, Converter={StaticResource timeSpanConverter}}"
                       Height="28" HorizontalAlignment="Left" Margin="98,0,0,6" VerticalAlignment="Bottom" Width="68" Name="averageDelayTextBox" />
                <Button Content="Use As Lead In" Height="23" HorizontalAlignment="Left" Margin="172,0,0,10" Name="useAsLeadInButton" 
                        VerticalAlignment="Bottom" Width="98" Click="UseAsLeadInButtonClick" IsEnabled="{Binding Path=Characterization.AnySamples}" />
            </Grid>
        </TabItem>
            
    </TabControl>
</Window>
